package com.sinoglobal.wallet.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 *  Fragment基类
 *  @author KeZhuang
 */
public abstract class W_SinoBaseFragment extends android.support.v4.app.Fragment {
	protected FragmentActivity mActivity;
	protected FragmentManager mFragmentManager;
	
	public abstract View createView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState);
	public abstract void findView(View contentView);
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View contentView = createView(inflater,container,savedInstanceState);
		mActivity = getActivity();
		mFragmentManager = getFragmentManager();
		findView(contentView);
		return contentView;
	}
	
	/**
	 *  获得Fragment的tag
	 * @param fragment 需要获得tag的fragment对象
	 * @return tag标签
	 */
	public String getFragmentTag(Fragment fragment){
		String tag = fragment.getClass().getSimpleName();
		return tag;
	}
	
	/**
	 * intent封装 ,不支持参数,无参跳转
	 * @param toClsActivity 需要跳转到的activity
	 */
	public void goIntent(Class<?> toClsActivity) {
		goIntent(toClsActivity, null);
	}
	
	/**
	 * intent封装 ,支持参数携带
	 * @param toClsActivity 需要跳转到的activity 
	 * @param bundle 参数封装
	 */
	public void goIntent(Class<?> toClsActivity, Bundle bundle) {
		Intent intent = new Intent(getActivity(), toClsActivity);
		if (bundle != null) {
			intent.putExtras(bundle);
		}
		startActivity(intent);
	}

	/**
	 * intent封装 ,隐式跳转
	 * @param action activity的action
	 */
	public void goIntent(String action){
		Intent intent = new Intent(action);
		startActivity(intent);
	}
}
